﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;
using System.Web.Configuration;
using System.ServiceModel;
using BookClubIt.Processor;
using DTO = BookClubIt.DTO;
using System.Web.UI.HtmlControls;

namespace BookClubIt.UserControls
{

    public partial class clubmenu : BaseUserControl 
	{
		protected void Page_Load(object sender, EventArgs e)
        {
         

            DTO.BookClub club = BookClubProcessorInstance.GetBookClubById(CID);

            //get book club avatar
            DTO.Members members = MemberProcessorInstance.GetBookClubMembersById(CID);
            string avatarpath = "../avatars/club/";
            imgBookClubAvatar.ImageUrl = avatarpath + club.AvatarURL;
           imgBookClubAvatar.AlternateText = club.Name;

           DTO.Members pendingMembers = MemberProcessorInstance.GetPendingBookClubMembersById(CID);

            // get member count of book club
           var MemberCnt = members.Count().ToString();


           lnkOverview.NavigateUrl = "~/bookclub/default.aspx?id=" + CID;
           lnkMembers.NavigateUrl = "~/bookclub/members.aspx?id=" + CID;
            lnkMembers.Text = "<i class='icon-user'></i> Members (" + MemberCnt + ")";
            lnkBookshelf.NavigateUrl = "~/bookclub/bookshelf.aspx?id=" + CID;
            lnkMeetings.NavigateUrl = "~/bookclub/meetings.aspx?id=" + CID;
            lnkDiscussions.NavigateUrl = "~/bookclub/discussions.aspx?id=" + CID;
            lnkInvite.NavigateUrl = "~/bookclub/invite.aspx?id=" + CID;
            lnkEditClub.NavigateUrl = "~/bookclub/editbookclub.aspx?id=" + CID;
            lnkSendMessage.NavigateUrl = "~/bookclub/message.aspx?id=" + CID;
        //    lnkPolls.NavigateUrl = "~/bookclub/polls.aspx?id=" + bid;
            lnkActivity.NavigateUrl = "~/bookclub/activity.aspx?id=" + CID;
            lnkchangeavatar.NavigateUrl = "~/bookclub/editbookclub.aspx?id=" + CID;
            lnkDeleteClub.NavigateUrl = "~/bookclub/delete.aspx?id=" + CID;

           
            string CurrentUri = Page.Request.Url.AbsoluteUri;
            if (CurrentUri.Contains("default.aspx"))
            {
                liHome.Attributes.Add("class","active");
                Page.Title = club.Name + " Home | Bookclubit.com";
            }
            else if (CurrentUri.Contains("members.aspx"))
            {
                liMembers.Attributes.Add("class", "active");
                Page.Title = club.Name + " Members | Bookclubit.com";
            }
            else if (CurrentUri.Contains("bookshelf.aspx"))
            {
                liBookshelf.Attributes.Add("class", "active");
                Page.Title = club.Name + " Book Shelf | Bookclubit.com";
            }
            else if (CurrentUri.Contains("discussions.aspx") || CurrentUri.Contains("topic.aspx"))
            {
                liDiscussions.Attributes.Add("class", "active");
                Page.Title = club.Name + " Discussions | Bookclubit.com";
            }
            //else if (CurrentUri.Contains("polls.aspx"))
            //{
            //    liPolls.Attributes.Add("class", "active");
            //    Page.Title = club.Name + " Polls | Bookclubit.com";
            //}
            else if (CurrentUri.Contains("invite.aspx"))
            {
                liInvite.Attributes.Add("class", "active");
                Page.Title = " Invite Friends To " +club.Name+" | Bookclubit.com";
            }
            else if (CurrentUri.Contains("editbookclub.aspx"))
            {
                liEditClub.Attributes.Add("class", "active");
                Page.Title = "Edit " + club.Name + " | Bookclubit.com";
            }
            else if (CurrentUri.Contains("meetings.aspx"))
            {
                liMeetings.Attributes.Add("class", "active");
                Page.Title = club.Name + " Meetings | Bookclubit.com";
            }
            else if (CurrentUri.Contains("meetingdetail.aspx"))
            {
                liMeetings.Attributes.Add("class", "active");
            }
            else if (CurrentUri.Contains("message.aspx"))
            {
                liSendMessage.Attributes.Add("class", "active");
                Page.Title = club.Name + " Message | Bookclubit.com";
            }
            else if (CurrentUri.Contains("activity.aspx"))
            {
                liActivity.Attributes.Add("class", "active");
                Page.Title = club.Name + " Activity | Bookclubit.com";
            }
            else if (CurrentUri.Contains("delete.aspx"))
            {
                liDeleteClub.Attributes.Add("class", "active");
                Page.Title = " Delete " +club.Name+ " | Bookclubit.com";
            }

            if (pendingMembers.Count > 0 && (BookClubProcessorInstance.IsAdmin(CurrentUserId, CID) || BookClubProcessorInstance.IsLeader(CurrentUserId, CID)))
            {
                if (CurrentUri.Contains("members.aspx"))
                {
                    liMembers.Attributes.Add("class", "info active");
                    lnkMembers.Attributes.Add("class", "active");
                }
                else
                {
                    liMembers.Attributes.Add("class", "info");
                }
            }

           string path = HttpContext.Current.Request.Url.AbsolutePath;

           if (BookClubProcessorInstance.IsLeader(CurrentUserId, CID))
           {
               liEditClub.Visible = true;
               liSendMessage.Visible = true;
              // liPolls.Visible = true;
               liDeleteClub.Visible = true;
               lnkchangeavatar.Visible = true;
           }
           else
           {

               lnkchangeavatar.Visible = false;
           }

           if (BookClubProcessorInstance.IsBookClubMember(CurrentUserId, CID))
           {

               liInvite.Visible = true;
           }
           else
           {
               liInvite.Visible = false;
           }



		}
      
	}
}